def isPrime(p):
    if p == 1: return False
    test = True
    t = p - 1
    while t > 1:
        if not p % t:
            test = False
            break
        t -= 1
    return test


k = input()
o = []
for g in range(len(k) + 1):
    for t in range(g, len(k) + 1):
        if g == t:
            continue
        p = int(k[g:t])
        if isPrime(p):
            o += [p]
print(max(o)if o else 0)



